<%-- 
/*
Assignment 1
Class ID        : SE0691
Group           : 1
Due Date        : 20 November 2012
I declare that this assignment is my own work
in accordance with FPT Policy.
*/
--%>

<%@page import="edu.fpt.dal.ApartmentDAL"%>
<%@page import="edu.fpt.hib.Apartment"%>
<%@page import="edu.fpt.dal.UsersDAL"%>
<%@page import="edu.fpt.hib.Users"%>
<%@page import="edu.fpt.dal.ServicesDAL"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Stop using services</title>
        <style type="text/css"> <!--@import url("../style.css");--></style>
        <script>function goBack()  {  window.history.back()  }</script>
    </head>
    <body>

        <%@include file="template/header.jsp" %>

        <div id="page">

            <%
                if (ServicesDAL.getByServicesID(request.getParameter("serviceid")) == null) {
            %>
            Services Not Found!
            <input class="searchsubmit" type='button' value='Back' onclick='goBack()'>
            <% } else {
                Users user = UsersDAL.getUsersHQL(session.getAttribute("currentUser").toString());
                Apartment apart = ApartmentDAL.getApartmentByUserHQL(user.getUserId());
                String usingNews = apart.getUsingServices();
                usingNews = ServicesDAL.removeFromList(usingNews, request.getParameter("serviceid"));
                apart.setUsingServices(usingNews);
                ApartmentDAL.update(apart);
                response.sendRedirect("myservices.jsp");
                               }
            %>
            <input class="searchsubmit" type='button' value='Back' onclick='goBack()'>
        </div>
        <%@include file="template/footer.jsp" %>
    </body>
</html>
